package com.example.hello_world.BroadcastReceiver;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.hello_world.R;

public class Broadcast extends AppCompatActivity {

    private Button sendBtn,staticBtn;
    private MyBroadcastReceiver broadcastReceiver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broadcast);
        sendBtn=findViewById(R.id.sendBroad);
        broadcastReceiver=new MyBroadcastReceiver();

        IntentFilter filter=new IntentFilter();
        filter.addAction("com.example.hello_world");
        registerReceiver(broadcastReceiver,filter);
        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getApplicationContext(),BroadcastB.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(broadcastReceiver);
    }
}